package com.qf.util;

import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * 2019/10/11
 * Administrator
 * springboot1011
 * 面向对象面向君  不负代码不负卿
 */
//设置数据源
    @Configuration
public class DatasourceConfig {

        @Bean  //默认对象名是方法名，但是可以通过name属性修改对象名@Bean(name="")
        @Primary
        @ConfigurationProperties(prefix = "spring.datasource.primary")
        public DataSource first(){
            return DataSourceBuilder.create().build();
        }


        @Bean
        @ConfigurationProperties(prefix = "spring.datasource.secondary")
        public DataSource two(){
            return DataSourceBuilder.create().build();
        }

}
